// pages/search_content/index.js
const appInstance = getApp()
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    image: 'https://ts1.cn.mm.bing.net/th/id/R-C.a217646500d039d0a039e0a555fa958e?rik=AQVEVmbiBPcN6g&riu=http%3a%2f%2fwww.qifeiye.com%2fqfy-content%2fuploads%2f2017%2f12%2fda7056bc7be73c97caa79618367dc366.gif%3fattachment_id%3d52381&ehk=S28gMPGLVUZaiwtzsYiNAXD%2b7Y226fOrYRTesFkCd3I%3d&risl=&pid=ImgRaw&r=0',
    pop_project_selection:false,
    service_config_id:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let search_content = options.search_content
    let url = appInstance.globalData.request_url + 'search_content'
    let data = {
      search_content: search_content,
    }
    console.log(url)
     let that = this
     wx.login({
      success: (res) => {
        wx.request({
          // url: appInstance.globalData.request_url + 'search_content', //仅为示例，并非真实的接口地址
          url: url, //仅为示例，并非真实的接口地址
          data: Object.assign({wx_code:res.code},data),
          dataType:"json",
          header: {
            'content-type': 'application/json' // 默认值
            // 'content-type': 'null' // 默认值
          },
          method:'POST',
          success (res) {
            // console.log(res.data.result)
            that.analysis_reps_data(res.data.result)
          },
          fali (err) {
            console.log(err)
          }
        })
      },
    })
 
  },
  get_service_options(e){
    console.log(e)
    this.setData({service_config_id:e.detail.value });
  },
  analysis_reps_data(resp_data){
    console.log(resp_data)
    if (!resp_data){
      this.setData({
        display_image:true
      })
    }else{
      let search_data = resp_data.resp_data
      let that = this
      if (resp_data.status == 200){
        // 搜索记录跳转
        that.setData({search_data:search_data})
      }else{
        // 提示用户无搜索记录
        console.log("无搜索记录")
        that.setData({search_data:[],display_image:true})
      }
    }
  },
  pop_project_selection(e){
    console.log(e)
    let search_records_details_id = e.currentTarget.dataset.id

    this.setData({
      pop_project_selection:true,
      search_records_details_id:search_records_details_id
    })
  },
  onVisibleChange(e) {
    this.setData({
      pop_project_selection: false,
    });
  },

  navigateTo_ServiceDetail(){
    let search_records_details_id = this.data.search_records_details_id
    let service_config_id = this.data.service_config_id
    if(service_config_id){
      wx.navigateTo({
        url: `/pages/service_detail/index?search_records_details_id=${search_records_details_id}&service_config_id=${service_config_id}`,
      })
    }else{
      wx.showToast({
        title: '请勾选服务项目',
        duration: 2000
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this
    let url = appInstance.globalData.request_url + 'api/query/service_config'
    let data = {}
    wx.login({
     success: (res) => {
       wx.request({
         // url: appInstance.globalData.request_url + 'search_content', //仅为示例，并非真实的接口地址
         url: url, //仅为示例，并非真实的接口地址
         data: Object.assign({wx_code:res.code},data),
         dataType:"json",
         header: {
           'content-type': 'application/json' // 默认值
           // 'content-type': 'null' // 默认值
         },
         method:'GET',
         success (res) {
           // console.log(res.data.result)
           console.log(res)
           let service_data_list = res.data.data
           that.setData({service_data_list:service_data_list})

         },
         fali (err) {
           console.log(err)
           that.setData({service_data_list:[]})
         }
       })
     },
   })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})